var app = getApp(), Toast = require("../../libs/zanui/toast/toast");

Page({
    data: {
        category: [],
        selectedId: "",
        scroll: !0,
        fixed: !0,
        cate_height: 45,
        display: [ {
            id: 0,
            title: "默认排序"
        }, {
            id: 1,
            title: "离我最近"
        }, {
            id: 2,
            title: "人气最高"
        } ],
        orderId: 0,
        od_height: 35,
        pages: 1,
        hide: !0,
        more: !0,
        refresh: !0
    },
    onLoad: function(t) {
        var a = this;
        app.viewCount();
        var e = t.id;
        e && (a.setData({
            selectedId: e
        }), a.getList(e)), app.util.footer(a);
    },
    getList: function(t) {
        var e = this;
        app.util.request({
            url: "entry/wxapp/item",
            cachetime: "0",
            data: {
                cid: t,
                act: "list",
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) e.showIconToast(t.errmsg); else {
                    var a = t.data.data.list;
                    e.setData({
                        category: t.data.data.category,
                        list: a,
                        total: a.length
                    });
                }
            }
        });
    },
    handleTabChange: function(e) {
        var s = this;
        app.util.request({
            url: "entry/wxapp/item",
            cachetime: "0",
            data: {
                cid: e.detail,
                act: "list",
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) s.showIconToast(t.errmsg); else {
                    var a = t.data.data.list;
                    s.setData({
                        list: a,
                        selectedId: e.detail
                    }), 0 == a.length && s.setData({
                        more: !0
                    });
                }
            }
        });
    },
    displayOrderChange: function(t) {
        var s = this, a = t.detail;
        s.setData({
            orderId: a,
            pages: 1,
            more: !0,
            refresh: !0
        }), 0 == a ? s.getList(s.data.selectedId) : 1 == a ? wx.getLocation({
            type: "gcj02",
            success: function(t) {
                var a = t.latitude, e = t.longitude;
                s.setData({
                    lat: a,
                    lng: e
                }), app.util.request({
                    url: "entry/wxapp/item",
                    cachetime: "0",
                    data: {
                        lat: a,
                        lng: e,
                        op: "location",
                        cid: s.data.selectedId,
                        m: "superman_hand2"
                    },
                    success: function(t) {
                        if (t.data.errno) s.showIconToast(t.errmsg); else {
                            var a = t.data.data.list;
                            s.setData({
                                list: a,
                                total: a.length
                            });
                        }
                    }
                });
            }
        }) : app.util.request({
            url: "entry/wxapp/item",
            cachetime: "0",
            data: {
                op: "popular",
                cid: s.data.selectedId,
                m: "superman_hand2"
            },
            success: function(t) {
                if (t.data.errno) s.showIconToast(t.errmsg); else {
                    var a = t.data.data.list;
                    s.setData({
                        list: a,
                        total: a.length
                    });
                }
            }
        });
    },
    onReachBottom: function() {
        var i = this;
        if (i.data.refresh) if (i.data.total < 10) i.setData({
            more: !1
        }); else {
            i.setData({
                hide: !1
            });
            var r = i.data.pages + 1, t = "", a = "", e = "";
            1 == i.data.orderId ? (t = "location", a = i.data.lat, e = i.data.lng) : 2 == i.data.orderId && (t = "popular"), 
            app.util.request({
                url: "entry/wxapp/item",
                cachetime: "0",
                data: {
                    page: r,
                    op: t,
                    lat: a,
                    lng: e,
                    cid: i.data.selectedId,
                    m: "superman_hand2"
                },
                success: function(t) {
                    if (i.setData({
                        hide: !0
                    }), 0 == t.data.errno) {
                        var a = t.data.data.list;
                        if (0 < a.length) {
                            var e = i.data.list;
                            i.setData({
                                total: e.length
                            });
                            var s = e.concat(a);
                            i.setData({
                                list: s,
                                pages: r
                            });
                        } else i.setData({
                            more: !1,
                            refresh: !1
                        });
                    } else i.showIconToast(t.errmsg);
                }
            });
        }
    },
    showIconToast: function(t) {
        var a = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "fail";
        Toast({
            type: a,
            message: t,
            selector: "#zan-toast"
        });
    }
});